<?php
/**
 * Created by PhpStorm.
 * User: 王松
 * Time: 2017/6/13 15:46
 */

namespace App\Project\Filters;

class FamilyHistoryFilter extends FilterAbstract
{
    protected function forExtend()
    {
        $extend = $this->request->input('extend');

        $map = [];

        if (is_array($extend)) {

            $length = count($this->request->input('extend'));

            for ($i = 0; $i < $length; $i++) {
                $map['extend'][] = array_merge(
                    array_flip($this->getSonFieldsForEachRoot()), ['name' => 0]
                );
            }
        } else {
            $map['extend'] = 1;
        }

        return $map;
    }

    protected function getRootFieldsHasNoSon()
    {
        return [
            'id',
            'record_id',
            'diabetes',
            'hypertension',
            'chd',
            'embolism',
            'hyperlipidemia',
            'tumor',
            'extend',
            'remark',
        ];
    }

    protected function getRootFieldsHasSon()
    {
        return [
            'diabetes', 'hypertension', 'chd', 'embolism', 'hyperlipidemia', 'tumor'
        ];
    }

    protected function getSonFieldsForEachRoot()
    {
        return [
            'select',
            'lineal.father',
            'lineal.mother',
            'lineal.brother',
            'lineal.sister',
            'lineal.children',
            'notLineal.grandfather',
            'notLineal.grandmother',
            'notLineal.grandpa',
            'notLineal.grandma',
            'notLineal.uncle',
            'notLineal.aunt',
            'notLineal.wifeSister',
            'notLineal.motherBrother',
            'notLineal.other',
        ];
    }
}